{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "view-in-github"
   },
   "source": [
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/stable-diffusion-webui-colab/blob/main/dev/generator.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re, os\n",
    "\n",
    "colabname = r\"{{colabname}}\"\n",
    "modelurl = r\"{{modelurl}}\"\n",
    "modelname = r\"{{modelname}}\"\n",
    "modelvaeurl = r\"{{modelvaeurl}}\"\n",
    "modelvaename = r\"{{modelvaename}}\"\n",
    "modelpage = r\"{{modelpage}}\"\n",
    "modelpagename = r\"{{modelpagename}}\"\n",
    "thanks = r\"{{thanks}}\"\n",
    "\n",
    "##################### Please edit only this block ####################\n",
    "\n",
    "# For README.md\n",
    "new_modelpage = \"https://civitai.com/models/41206/coremixpure\"\n",
    "\n",
    "new_colabname = \"coremixpure_webui_colab\"\n",
    "\n",
    "# If from civitai model_creator_username/model_name\n",
    "new_modelpagename = \"CornmeisterNL/coremixpure\"\n",
    "\n",
    "# If no one has suggested it, please change 'person' to your username or delete all the strings like new_thanks = \"\"\n",
    "# new_thanks = \"<br /> (Thanks to person for the suggestion ❤)\"\n",
    "new_thanks = \"<br /> (Thanks to Koneko❁ུ۪۪♡ for the suggestion ❤)\"\n",
    "\n",
    "# For WebUI\n",
    "new_modelname = \"coremixpure_v10.safetensors\"\n",
    "\n",
    "new_modelvaename = \"coremixpure_v10.vae.pt\"\n",
    "\n",
    "# If link like https://civitai.com/api/download/models/16553?type=Model&format=SafeTensor\n",
    "# please use new_modelurl = \"\\\\\\\"https://civitai.com/api/download/models/16553?type=Model&format=SafeTensor\\\\\\\"\"\n",
    "new_modelurl = \"https://huggingface.co/ckpt/coremixpure/resolve/main/coremixpure_v10.safetensors\"\n",
    "\n",
    "new_modelvaeurl = \"https://huggingface.co/ckpt/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt\"\n",
    "\n",
    "#######################################################################\n",
    "\n",
    "with open(\"readme_in\", 'r') as f:\n",
    "    input_text_readme_in = f.read()\n",
    "input_text1_readme_in = re.sub(modelpage, new_modelpage, input_text_readme_in)\n",
    "input_text2_readme_in = re.sub(modelpagename, new_modelpagename, input_text1_readme_in)\n",
    "input_text3_readme_in = re.sub(thanks, new_thanks, input_text2_readme_in)\n",
    "input_text4_readme_in = re.sub(colabname, new_colabname, input_text3_readme_in)\n",
    "with open(\"readme_out\", 'w') as f:\n",
    "    f.write(input_text4_readme_in)\n",
    "\n",
    "output_file_lite = os.path.join(os.path.dirname(os.getcwd()), \"lite\", f\"{new_colabname}.ipynb\")\n",
    "file_lite = \"lite.ipynb\"\n",
    "with open(file_lite, 'r') as f:\n",
    "    input_text_lite = f.read()\n",
    "output_text1_lite = re.sub(colabname, new_colabname, input_text_lite)\n",
    "output_text2_lite = re.sub(modelurl, new_modelurl, output_text1_lite)\n",
    "output_text3_lite = re.sub(modelname, new_modelname, output_text2_lite)\n",
    "output_text4_lite = re.sub(modelvaeurl, new_modelvaeurl, output_text3_lite)\n",
    "output_text5_lite = re.sub(modelvaename, new_modelvaename, output_text4_lite)\n",
    "with open(output_file_lite, 'w') as f:\n",
    "    f.write(output_text5_lite)\n",
    "\n",
    "output_file_stable = os.path.join(os.path.dirname(os.getcwd()), \"stable\", f\"{new_colabname}.ipynb\")\n",
    "file_stable = \"stable.ipynb\"\n",
    "with open(file_stable, 'r') as f:\n",
    "    input_text_stable = f.read()\n",
    "output_text1_stable = re.sub(colabname, new_colabname, input_text_stable)\n",
    "output_text2_stable = re.sub(modelurl, new_modelurl, output_text1_stable)\n",
    "output_text3_stable = re.sub(modelname, new_modelname, output_text2_stable)\n",
    "output_text4_stable = re.sub(modelvaeurl, new_modelvaeurl, output_text3_stable)\n",
    "output_text5_stable = re.sub(modelvaename, new_modelvaename, output_text4_stable)\n",
    "with open(output_file_stable, 'w') as f:\n",
    "    f.write(output_text5_stable)\n",
    "\n",
    "output_file_nightly = os.path.join(os.path.dirname(os.getcwd()), \"nightly\", f\"{new_colabname}.ipynb\")\n",
    "file_nightly = \"nightly.ipynb\"\n",
    "with open(file_nightly, 'r') as f:\n",
    "    input_text_nightly = f.read()\n",
    "output_text1_nightly = re.sub(colabname, new_colabname, input_text_nightly)\n",
    "output_text2_nightly = re.sub(modelurl, new_modelurl, output_text1_nightly)\n",
    "output_text3_nightly = re.sub(modelname, new_modelname, output_text2_nightly)\n",
    "output_text4_nightly = re.sub(modelvaeurl, new_modelvaeurl, output_text3_nightly)\n",
    "output_text5_nightly = re.sub(modelvaename, new_modelvaename, output_text4_nightly)\n",
    "with open(output_file_nightly, 'w') as f:\n",
    "    f.write(output_text5_nightly)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
